/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
 */

package org.opengauss.admin.plugin.vo;

import lombok.Data;

/**
 * Host base info vo
 *
 * @since 2025/7/22
 */
@Data
public class HostBaseInfoVo implements Comparable<HostBaseInfoVo> {
    private String cpuCoreNum;
    private String cpuUsing;
    private String remainingMemory;
    private String availableDiskSpace;

    /**
     * Is empty
     *
     * @return the boolean
     */
    public boolean isEmpty() {
        return cpuCoreNum == null && cpuUsing == null && remainingMemory == null && availableDiskSpace == null;
    }

    @Override
    public int compareTo(HostBaseInfoVo o) {
        if (isEmpty() || o.isEmpty()) {
            return 0;
        }

        try {
            int compared = Integer.compare(Integer.parseInt(o.getCpuCoreNum()), Integer.parseInt(getCpuCoreNum()));
            if (compared != 0) {
                return compared;
            }
        } catch (NumberFormatException e) {
            return 0;
        }

        try {
            int cpuUsingCompare = Float.compare(Float.parseFloat(getCpuUsing()), Float.parseFloat(o.getCpuUsing()));
            if (cpuUsingCompare != 0) {
                return cpuUsingCompare;
            }
        } catch (NumberFormatException e) {
            return 0;
        }

        try {
            int remainingMemoryCompare = Double.compare(
                    Double.parseDouble(o.getRemainingMemory()), Double.parseDouble(getRemainingMemory()));
            if (remainingMemoryCompare != 0) {
                return remainingMemoryCompare;
            }
        } catch (NumberFormatException e) {
            return 0;
        }

        try {
            return Float.compare(
                    Float.parseFloat(o.getAvailableDiskSpace()), Float.parseFloat(getAvailableDiskSpace()));
        } catch (NumberFormatException e) {
            return 0;
        }
    }
}
